<template>
  <div class="mapping-page">
    <!-- 头部盒子 -->
    <div class="header">
      <!-- 页面标题 -->
      <div class="title">
        <h4>物料属性映射</h4>
      </div>
      <!-- 右侧盒子 -->
      <div class="right">
        <!-- 搜索表单 -->
        <el-form :inline="true" size="small">
          <el-form-item>
            <el-input placeholder="显示名称"></el-input>
          </el-form-item>
          <el-form-item></el-form-item>
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
        </el-form>

        <!-- 新增按钮 -->
        <el-button
          style="height: 32px"
          type="primary"
          size="small"
          plain
          @click="showDrawer = true"
          >新增</el-button
        >
      </div>
    </div>

    <!-- table表格 -->
    <div class="table">
      <el-table :data="PropertyList" border style="width: 100%">
        <el-table-column prop="date" label="属性名称"></el-table-column>
        <el-table-column prop="name" label="属性类型"></el-table-column>
        <el-table-column prop="address" label="卡片变量"></el-table-column>
        <el-table-column
          prop="address"
          label="Erp名称"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="SW属性名"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="表格列名"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="顺位"
          width="70"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="显示"
          width="70"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="校验"
          width="70"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="编辑"
          width="70"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="显示名称"
          width="100"
        ></el-table-column>
        <el-table-column prop="address" label="操作" width="150">
          <template>
            <el-button size="mini" @click="edit">编辑</el-button>
            <!-- <el-button size="mini" type="danger">删除</el-button> -->
            <el-popconfirm
              title="这是一段内容确定删除吗？"
              @confirm="confirmDel"
            >
              <el-button
                style="margin-left: 10px"
                size="mini"
                type="danger"
                slot="reference"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 编辑和新增的抽屉 -->
    <el-drawer
      :visible.sync="showDrawer"
      title="title"
      :with-header="false"
      :before-close="handleClose"
      size="50%"
    >
      <el-tabs v-model="activeName" style="padding: 0 20px">
        <!-- tab栏切换 -->
        <el-tab-pane label="物料属性" name="first">
          <!-- 表单 -->
          <el-form label-width="100px" ref="formRef">
            <el-form-item label="属性名称">
              <el-select placeholder="请选择" style="width: 80%">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="PDM卡片名称">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="ERP属性名称">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="Sw属性名称">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="Excel列名(导入Excel设置)">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="显示名称">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="属性类型值">
              <el-select placeholder="请选择" style="width: 80%">
                <el-option label="文本" value="1"></el-option>
                <el-option label="数字" value="2"></el-option>
                <el-option label="下拉框" value="3"></el-option>
                <el-option label="树形结构" value="4"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="表名称">
              <el-input style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="显示顺序">
              <el-input-number
                v-model="num1"
                @change="handleChange1"
                :min="1"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="列宽">
              <el-input-number
                v-model="num2"
                @change="handleChange2"
                :min="1"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="功能选择">
              <el-checkbox-group v-model="checkList">
                <el-checkbox label="编辑状态"></el-checkbox>
                <el-checkbox label="物料工具"></el-checkbox>
                <el-checkbox label="是否校验"></el-checkbox>
                <el-checkbox label="显示BOM"></el-checkbox>
                <el-checkbox label="显示历史数据整理工具"></el-checkbox>
                <el-checkbox label="同步ERP"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item style="text-align: center">
              <el-button type="primary">保存</el-button>
              <el-button @click="cancel">取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <!-- tab栏 -->
        <el-tab-pane label="校验规则" name="second">
          <div
            class="rule"
            style="display: flex; justify-content: space-between"
          >
            <div>
              <!-- 表单 -->
              <el-form label-width="120px">
                <el-form-item label="校验类型">
                  <el-select placeholder="请选择">
                    <el-option label="不为空" value="不为空"></el-option>
                    <el-option label="长度" value="长度"></el-option>
                    <el-option label="包含" value="包含"></el-option>
                    <el-option label="不包含" value="不包含"></el-option>
                    <el-option label="相等" value="相等"></el-option>
                    <el-option label="最大值" value="最大值"></el-option>
                    <el-option label="最小值" value="最小值"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="校验值">
                  <el-input></el-input>
                </el-form-item>
                <el-form-item label="所处流程状态">
                  <el-input></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary">添加</el-button>
                </el-form-item>
              </el-form>
            </div>

            <!-- 表格 -->
            <div>
              <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column
                  prop="date"
                  label="校验类型"
                  width="80"
                ></el-table-column>
                <el-table-column
                  prop="name"
                  label="校验值"
                  width="80"
                ></el-table-column>
                <el-table-column
                  prop="address"
                  label="所处流程状态"
                  width="120"
                ></el-table-column>
                <el-table-column prop="address" label="操作" width="60">
                  <template>
                    <el-button size="mini" type="danger">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
  </div>
</template>

<script>
import { GetAllItemInfoPropertySettingsApi } from "@/api/mapping";
export default {
  data() {
    return {
      PropertyList: [],
      showDrawer: false,
      chechList: [],
      activeName: "first",
      num1: 1,
      num2: 1,
      checkList: [],
      tableData: [],
    };
  },
  created() {
    this.GetAllItemInfoPropertySettings();
  },

  methods: {
    async GetAllItemInfoPropertySettings() {
      const res = await GetAllItemInfoPropertySettingsApi();
      console.log(res);
      this.PropertyList = res.data;
    },
    // 封装一个处理弹窗关闭的方法：需要关闭的时候调用，清楚表单的数据，初始化表单
    handleClose() {
      this.showDrawer = false;
    },
    cancel() {
      this.showDrawer = false;
    },
    edit() {
      this.showDrawer = true;
    },
    // 确认删除的回调
    confirmDel() {
      this.$message.success("删除成功");
    },
    handleChange1() {},
    handleChange2() {},
  },
};
</script>

<style lang="scss" scoped>
.mapping-page {
  background-color: #fff;
  padding: 0 50px 50px 50px;

  .header {
    display: flex;
    text-align: center;
    justify-content: space-between;
    align-items: center;
    // padding: 0 50px;

    .title {
      font-size: 20px;
    }

    .right {
      text-align: center;
      display: flex;
      padding-top: 30px;
    }
  }

  .table {
  }

  .dialogBox {
    margin: 0 auto;
  }

  .drawerBox {
    // padding: 20px 40px;

    .rule {
    }
  }
}
</style>


